package com.qire.manhua.controller;

import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.common.basic.ObjectUtil;
import com.qire.common.constant.Navigation;
import com.qire.common.constant.TeensModeManage;
import com.qire.common.support.base.EventController;
import com.qire.common.widget.adapter.auto.AutoVariable;
import com.qire.manhua.activity.AccountsAssociatedActivity;
import com.qire.manhua.databinding.LayoutAccountsAssociatedItemBinding;
import com.qire.manhua.dialog.TeensPasswordAuthorizeDialog;
import com.qire.manhua.model.enumeration.TeensModeScene;
import com.qire.manhua.model.viewModel.impl.AccountsAssociatedViewModel;
import com.qire.manhua.model.viewModel.impl.AccountsAssociatedViewModel.AccountsAssociatedItemViewModel;

import androidx.annotation.NonNull;

public class AccountsAssociatedController extends EventController<AccountsAssociatedActivity> implements AutoVariable<LayoutAccountsAssociatedItemBinding> {

    private AccountsAssociatedViewModel viewModel;

    public AccountsAssociatedController(@NonNull AccountsAssociatedActivity owner) {
        super(owner);
    }

    @Override
    protected void bindView() {
        owner.viewDataBinder().setAccountsAssociatedController(this);
    }

    @Override
    public void bindVariable(LayoutAccountsAssociatedItemBinding viewBind) {
        viewBind.setAccountsAssociatedController(this);
    }

    @Override
    protected void onCleared() {
        super.onCleared();
        this.viewModel = null;
    }

    public void onAddition(AccountsAssociatedViewModel viewModel) {
        this.viewModel = viewModel;
    }
    /**************************************************************************************************************/

    public void backBtnOnClick(View view) {
        owner.finish();
    }

    public void loginAccountBtnOnClick(View view) {
        viewModel.toggleLoginAccount();
    }

    public void accountsAssociatedAddBtnOnClick(View view) {
        AntsRouter.ROUTER.buildCard(Navigation.Page.AccountsAssociatedAddPage).navigation();
    }

    public void accountItemOnClick(View view) {
        AccountsAssociatedItemViewModel itemViewModel = ObjectUtil.as(view.getTag(), AccountsAssociatedItemViewModel.class);
        if(ObjectUtil.nonNull(itemViewModel)) {
            if(TeensModeManage.teensModeEnable()) {
                new TeensPasswordAuthorizeDialog(owner, TeensModeScene.Logout, itemViewModel::toggle).show();
            } else {
                itemViewModel.toggle();
            }
        }
    }
}
